package top.littlematch.feign;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@RestController
public class FeignApplication {
    public static void main(String[] args){
        SpringApplication.run(FeignApplication.class, args);
    }
    //调用的服务名，以接口的方式定义
    @FeignClient("eureka-client")
    public interface BaseService {
        //调用的方法所暴露的url,其实就相当于页面调用方法一样
        @RequestMapping(value = "/hello", method = RequestMethod.GET)
        public String hello(@RequestParam("name") String name);
    }

    /**
     * 注入该方法，idea这里可能会报红
     *  这里就如dubbo的方法调用，只是这里需重新定义个接口接收方法
     *  基于http会多这一步，但也因为基于http其扩展性很强,能轻易实现与其他语言基于http服务调用
     */

    @Autowired
    private BaseService baseService;


    @RequestMapping("/hello")
    public String hello(@RequestParam("name")String name){
        //调用方法
        return baseService.hello(name);
    }
}
